home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / Intuition / boopsi / democlasslib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  3.2 KB  |  151 lines

  1. /* democlasslib.c -- demonstration of         :ts=8
  2.  * using a public image class from a library.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989-1999 Amiga, Inc.
  7.  
  8. Executables based on this information may be used in software
  9. for Amiga computers. All other rights reserved.
  10. This information is provided "as is"; no warranties are made.
  11. All use is at your own risk, and no liability or responsibility
  12. is assumed.
  13. */
  14.  
  15. #include "sysall.h"
  16.  
  17. #define D(x)    x
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct Library    *MyClassBase;
  21.  
  22. ULONG    myiflags = CLOSEWINDOW;
  23.  
  24. struct Image    *myimage;
  25.  
  26. main()
  27. {
  28.     struct DrawInfo    *GetScreenDrawInfo();
  29.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  30.     struct Window    *w;
  31.     struct DrawInfo    *drinfo;
  32.  
  33.     openAll();    /* get libraries open    */
  34.  
  35.     D( printf("got myclass.library at %lx\n", MyClassBase ) );
  36.  
  37.     D( printf("about to openwindow\n") );
  38.     w = OpenWindowTags( NULL,
  39.         WA_Title,    "Public Image Test Window",
  40.         WA_SimpleRefresh, TRUE,
  41.         WA_NoCareRefresh, TRUE,
  42.         WA_DepthGadget,    TRUE,
  43.         WA_DragBar,    TRUE,
  44.         WA_Left,    300,
  45.         WA_Top,        50,
  46.         WA_Width,    280,
  47.         WA_Height,    120,
  48.         WA_IDCMP,    myiflags,
  49.         WA_CloseGadget,    TRUE,
  50.             TAG_END );
  51.     D( printf("window at %lx\n ", w ) );
  52.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  53.  
  54.     drinfo = GetScreenDrawInfo( w->WScreen );
  55.  
  56.     /* create an image from my public class    */
  57.     myimage =  (struct Image *) NewObject(  NULL,  "emboxclass",
  58.             IA_WIDTH, 20,
  59.             IA_HEIGHT, 10,
  60.                 TAG_END );
  61.  
  62. #define XPOS    (40)
  63. #define YPOS    (20)
  64. #define XPOS2    (XPOS + 30)
  65.  
  66.     /* draw the image    */
  67.     DrawImageState( w->RPort, myimage, XPOS, YPOS, IDS_NORMAL, drinfo );
  68.  
  69.     /* draw the image    */
  70.     DrawImageState( w->RPort, myimage, XPOS2, YPOS, IDS_SELECTED, drinfo );
  71.  
  72.     /* go away and be done    */
  73.     goHandleWindow( w );
  74.  
  75.     FreeScreenDrawInfo( w->WScreen, drinfo );
  76.     CloseWindow( w );
  77.  
  78.     cleanup( "all done, disposing image before closelibrary." );
  79. }
  80.  
  81. /*
  82.  * try to get the system to flushlibs
  83.  */
  84. inciteExpunge()
  85. {
  86.     void *mem;
  87.  
  88. #define LOTS_O_MEM    (2000000L)
  89.  
  90.     if ( mem = (void *) AllocMem( LOTS_O_MEM, 0 ) )
  91.     {
  92.     D( printf("GOT MEM %lx!\n", mem ) );
  93.         FreeMem( mem, LOTS_O_MEM );
  94.     }
  95. }
  96.  
  97. cleanup( str )
  98. char    *str;
  99. {
  100.     if (str) printf("%s\n", str);
  101.  
  102.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  103.  
  104.     DisposeObject( myimage );
  105.     D( printf("have disposed image.\n") );
  106.  
  107.     D( printf("close class library %lx\n", MyClassBase ) );
  108.     if (MyClassBase) CloseLibrary(MyClassBase);
  109.  
  110.     D( printf("expunge ... ") );
  111.     inciteExpunge();
  112.     D( printf("done\n") );
  113.  
  114.     exit (0);
  115. }
  116.  
  117. /* exits via cleanup() if failure    */
  118. openAll()
  119. {
  120.     if (!(IntuitionBase =
  121.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  122.     { cleanup("no V36 intuition library\n"); }
  123.  
  124.     if (!(MyClassBase=(struct Library *)OpenLibrary("myclass.library", 36L)))
  125.     { cleanup("no myclass.library\n"); }
  126. }
  127.  
  128. goHandleWindow( w )
  129. struct Window    *w;
  130. {
  131.     struct IntuiMessage *imsg;
  132.     for(;;)
  133.     {
  134.     WaitPort( w->UserPort );
  135.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  136.     {
  137.         switch ( imsg->Class )
  138.         {
  139.         case CLOSEWINDOW:
  140.             ReplyMsg( (struct Message *) imsg );
  141.         return;
  142.  
  143.         default:
  144.         D( printf("unknown message \n", imsg->Class));
  145.         break;
  146.         }
  147.         ReplyMsg( (struct Message *) imsg );
  148.     }
  149.     }
  150. }
  151.